home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / LIBRARY / TOOLPAS2 / DIRC.PAS < prev    next >
Pascal/Delphi Source File  |  1991-05-18  |  2KB  |  101 lines

  1.  
  2. (*
  3.  * DirC - DIR file concatenation utility
  4.  *
  5.  * Written by Samuel H. Smith, 5-17-91
  6.  *
  7.  *)
  8.  
  9. var
  10.    infd:    text;
  11.    inbuf:   array[1..10000] of char;
  12.    outfd:   text;
  13.    outbuf:  array[1..20000] of char;
  14.  
  15.    line:    string;
  16.    p:       integer;
  17.  
  18.    mode:    (concat, expand);
  19.  
  20. procedure usage;
  21. begin
  22.    writeln('usage: dirc -concat INFILE OUTFILE');
  23.    writeln(' or    dirc -expand INFILE OUTFILE');
  24.    halt(1);
  25. end;
  26.  
  27. procedure concat_file;
  28. begin
  29.    readln(infd,line);
  30.    repeat
  31.       if line <> '' then
  32.       begin
  33.          p := pos('.',line);
  34.          if (p > 1) and (p < 10) and (line[23] = ' ') and (line[26] = '-') then
  35.          begin
  36.             writeln(outfd,line);
  37.             repeat
  38.                if eof(infd) then
  39.                   line := ''
  40.                else
  41.                   readln(infd,line);
  42.                p := pos('|',line);
  43.                if p > 0 then
  44.                   writeln(outfd,line);
  45.             until p = 0;
  46.             writeln(outfd);
  47.          end
  48.          else
  49.             readln(infd,line);
  50.       end
  51.       else
  52.          readln(infd,line);
  53.    until eof(infd);
  54. end;
  55.  
  56. procedure expand_file;
  57. begin
  58.    while not eof(infd) do
  59.    begin
  60.       readln(infd,line);
  61.       if line <> '' then
  62.          writeln(outfd,line);
  63.    end;
  64. end;
  65.  
  66. begin
  67.    if paramcount <> 3 then
  68.       usage;
  69.  
  70.    line := paramstr(1);
  71.    if line[1] <> '-' then
  72.       usage;
  73.  
  74.    case upcase(line[2]) of
  75.       'C':  mode := concat;
  76.       'E':  mode := expand;
  77.       else  usage;
  78.    end;
  79.  
  80.    assign(infd,paramstr(2));
  81.    reset(infd);
  82.    settextbuf(infd,inbuf);
  83.  
  84.    assign(outfd,paramstr(3));
  85.    rewrite(outfd);
  86.    settextbuf(outfd,outbuf);
  87.  
  88.    if mode = concat then
  89.       concat_file
  90.    else
  91.    if mode = expand then
  92.       expand_file
  93.    else
  94.       usage;
  95.  
  96.    close(infd);
  97.    close(outfd);
  98.  
  99. end.
  100.  
  101.